<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>The Portal Project</title>
        <link rel="stylesheet" type="text/css" href="tppStyles.css" />

        <script type="text/javascript" >
            function enableAdd()
            {
                document.getElementById('addProf').style.display = 'block';
                document.getElementById('chooseProf').style.display = 'none';
                document.getElementById('chooseProf').checked = 0;
            }

            function enableChoose()
            {
                document.getElementById('chooseProf').style.display = 'block';
                document.getElementById('addProf').style.display = 'none';
                document.getElementById('addProf').checked = 0;
            }

            function enableWeightAdd()
            {
                document.getElementById('addWeight').style.display = 'block';
                document.getElementById('chooseWeight').style.display = 'none';
                document.getElementById('chooseWeight').checked = 0;
            }
            function enableWeightChoose()
            {
                document.getElementById('chooseWeight').style.display = 'block';
                document.getElementById('addWeight').style.display = 'none';
                document.getElementById('addWeight').checked = 0;
            }


        </script>

    </head>
    <body><center>
            <a href = "index.php">
                <img src = "tppheaderbanner.jpg" alt = "The Portal Project" /></a>

            <?php
            session_start();
            $_POST = array_map('strip_tags', $_POST);
            include_once 'userManager.php';
            include_once 'courseManager.php';
            include_once 'linkManager.php';
            include_once 'settingManager.php';
            include_once 'professorManager.php';
            include_once 'calendarManager.php';

            if (isset($_GET['add']))
                $add = $_GET['add'];
            if (isset($_GET['edit']))
                $edit = $_GET['edit'];
            if (isset($_GET['submit']))
                $submit = $_GET['submit'];
            if (isset($_GET['delete']))
                $delete = $_GET['delete'];
            if (isset($_GET['complete']))
                $complete = $_GET['complete'];

            if (isset($_SESSION['userID'])) {
                $user = new User();
                $user = userManager::getUser($_SESSION['userID']);
                $name = $user->getFirstName();
                echo "<br>Welcome, $name! ";
                echo "<a href='index.php?edit=settings'>Edit Settings</a> | <a href='logout.php'>Logout</a><br><br>";

                $settings = new Setting();
                $settings = settingManager::getSettings($_SESSION['userID']);
                $calendar = $settings->getCalendar();
                $grades = $settings->getGrades();
                $links = $settings->getLinks();
                $facebook = $settings->getFacebook();
                $twitter = $settings->getTwitter();
                $tumblr = $settings->getTumblr();
                $linkedIn = $settings->getLinkedIn();
                $emailBool = $settings->getEmailBool();
                $textBool = $settings->getTextBool();

                $numModules = $calendar + 2 * $grades + $links + $facebook;

                $remainingCells = $numModules % 3;
                $rows = ($numModules - $remainingCells) / 3;
                $tableArray = array();
                $tableArray['course'] = $grades;
                $tableArray['social'] = $facebook;
                $tableArray['link'] = $links;
                $tableArray['assignment'] = $grades;
                $tableArray['calendar'] = $calendar;
                
                if ($edit == "settings") {
                    include 'settingModule.php';
                }

                //just adding a table border for now to tell what's going on //border = 1
                echo "<table  width=\"820\">";
                $i = 0;
                foreach ($tableArray as $module => $bool) {
                    if ($bool == "1") {
                        if ($i == 0)
                            echo "<tr>";
                        echo "<td width=\"40%\" valign=\"top\">";
                        echo "<p>";
                        include $module . "Module.php";
                        echo "</p>";
                        echo "</td>";
                        $i++;
                        if ($i == 3)
                            echo "</tr>";
                    }
                }
                echo "</table>";
            } else {
                echo "<p>The portal project combines your social life and your school life into one
                easy to access website. Join today! </p>";
                echo "<br>";
                include_once 'login.php';
                
                
            }
            echo "</ br>";
            ?>
        </center>
    </body>
</html>
